﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BCL.BaseLib;
using BCL.WPFComponent.Base;
using BCL.BaseLib.Basics;
namespace BCL.WPFComponent
{
    /// <summary>
    /// MainMune.xaml 的交互逻辑
    /// </summary>
    public partial class MainMune : BaseFunctionControl
    {
        //private int maxitemCount = 0;
        //private Style mune_Border;
        //private Style mune_TextBlock;
        //private Style muneImte_Border;
        public MainMune()
        {
            InitializeComponent();
            //ResourceDictionary rd=(ResourceDictionary)this.Resources.MergedDictionaries[0];

            //mune_Border = (Style)rd["mune_Border"];
            //muneImte_Border = (Style)rd["muneImte_Border"];
            //mune_TextBlock = (Style)rd["mune_TextBlock"];
        }

        public MainMune(FunctionEntity fe) : base(fe)
        {
            InitializeComponent();
            //Resources.MergedDictionaries[0].FindName
            //mune_Border = (Style)Resources.MergedDictionaries[0].FindName.FindName("mune_Border");
            //mune_TextBlock = (Style)Resources.MergedDictionaries[0].FindName.FindName("mune_TextBlock");
        }

        public override void LanguageBinding()
        {

        }

        private void BaseFunctionControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (BCLApplication.AppFunTree == null)
                return;
            foreach (var item in BCLApplication.AppFunTree)
                if(item.IsCreate)
                LoadFunction(item, MainPanel);
             //this.Width = maxitemCount + 2 * 72;
            //this.ActualHeight+= maxitemCount + 2 * 72;
        }


        private void LoadFunction(FunctionEntity fe, StackPanel panel)
        {
            UCMuneItem uCMuneItem = new UCMuneItem(fe);
            uCMuneItem.Margin = new Thickness(10);

            panel.Children.Add(uCMuneItem);
            //if (!fe.IsCreate || panel==null)
            //    return;
            //if (fe.ItemType == FunctionItemType.Group)
            //{
            //    StackPanel stack = new StackPanel { Orientation = Orientation.Horizontal };
            //    Border border = new Border { Child = new TextBlock { Text = fe.Title,Style= mune_TextBlock},Style=mune_Border };
            //    stack.Children.Add(border);
            //    panel.Children.Add(stack);
            //    foreach (var item in fe.Items)
            //        LoadFunction(item, stack);
            //    if (fe.Items.Count > maxitemCount)
            //        maxitemCount = fe.Items.Count;
            //}
            //else 
            //{
            //    Border border = new Border { Style= muneImte_Border };
            //    border.Child = new Image { Source = fe.Image.ToBitmap() };
            //    border.MouseDown += (send, e) => BCLApplication.MainForm.OpenFunction(fe);
            //    panel.Children.Add(border);

            //}
        }

    }
}
